<script lang="ts" setup>
import {ref} from "vue"
import pagination from "./pagination.vue"
import {useRouter} from 'vue-router'
import {getUserAttr} from "../serve.ts";

const
    router = useRouter(),
    itemData = ref({list: [], current: 1, size: 10, total: 0}),
    fromData = ref({size: 5, page: 1,type:'NEWS'}),
    load = ref(true),
    type = ref('NEWS'),
    title = ref('资讯收藏')
;

function openNewTab(t: string, ti: string) {
  if (type.value == t)return
  fromData.value = {size: 5, page: 1,type:t}
  type.value = t
  title.value = ti
  get()
}

function get() {
  getUserAttr({...fromData.value}).then((r:any)=>{
    itemData.value = r
    load.value = false
    // console.table(r['list'])
  })
}

get()

function sizeChange(size: number) {
  fromData.value.size = size
  get()
}

function currentChange(currPage: number) {
  fromData.value.page = currPage
  get()
}
function opNewTab(d:any) {
  const r = router.resolve({path:d.path,query:{id:d.id}})
  window.open(r.href,'_blank')
}
</script>

<template>
  <el-scrollbar style="overflow: hidden">
    <div v-loading="load" con element-loading-text="加载中...">
      <div travel>
        <div tr-top>
          <div dis>
            <div>收藏分类</div>
          </div>
        </div>
        <div class="news-list">
          <div v-for="(news, index) in [
              {title:'资讯收藏',type:'NEWS'},
              {title:'路线收藏',type:'ROUTE'},
              {title:'景点收藏',type:'ATTRACTION'}
          ]" :key="index" class="news-item" @click="openNewTab(news['type'],news['title'])">
            <span class="news-title">{{ news['title'] }}</span>
          </div>
        </div>
      </div>
      <div tr-right travel>
        <div tr-top>
          <div dis>
            <div>{{ title }}</div>
          </div>
        </div>
        <div v-if="type == 'NEWS'" class="news-list">
          <div v-for="(news, index) in itemData['list']" :key="index" class="news-item" @click="opNewTab({id:news['relateId'],path:'/information-details'})">
            <span class="news-date">{{ news['createdAt']}}</span>
            <span class="news-title">{{ news['name'] }}</span>
          </div>
        </div>
        <div v-if="type =='ROUTE'" v-for="(item, index) in itemData['list']" :key="index" class="item-wrapper" @click="opNewTab({id:item['relateId'],path:'/routeTon-details'})">
          <div class="content-wrapper">
            <!-- 左侧图片 -->
            <img :src="item['pic']" alt="图片" class="main-image">
            <!-- 右侧内容 -->
            <div class="content-container">
              <div class="route-item">
                <div class="route-content">
                  <h2 class="route-title">{{ item['name'] }}</h2>
                  <p class="route-description">{{ item['createdAt'] }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div v-if="type =='ROUTE'" style="width: 100%;height: 80px"/>
        <div v-if="type =='ATTRACTION'" v-for="(item, index) in itemData['list']" :key="index" class="item-wrapper"@click="opNewTab({id:item['relateId'],path:'/come-details'})">
          <div class="content-wrapper">
            <!-- 左侧图片 -->
            <img :src="item['pic']" alt="图片" class="main-image">
            <!-- 右侧内容 -->
            <div class="content-container">
              <div class="route-item">
                <div class="route-content">
                  <h2 class="route-title">{{ item['name'] }}</h2>
                  <p class="route-description">{{ item['createdAt'] }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div v-if="type =='ATTRACTION'" style="width: 100%;height: 80px"/>
        <div page>
          <pagination :pageCurrent="itemData?.current" :pageSize="itemData?.size"
                      :small="false" :total="itemData?.total"
                      class="page" @size-change="sizeChange" @current-change="currentChange"/>
        </div>
      </div>
    </div>
    <div style="position: fixed;bottom: 0;right: 0;left: 0;">
      <div style="width: 98%;margin: auto;height: 1px;background-color: #002B49;"/>
      <div class="copyright">© 2025 旅游网站</div>
    </div>
  </el-scrollbar>
</template>

<style lang="scss" scoped>
[page] {
  //padding: 20px 100px;
}
[con] {
  width: 90%;
  margin: 30px auto auto;
  font-family: 'Microsoft YaHei', sans-serif;
  background-color: white;
  padding-bottom: 25px;
  border-radius: 6px;
  display: flex;
  justify-content: start;
  //height: 100vh;
}

[travel] {
  width: 250px;
  //background-color: white;
  padding-bottom: 25px;
  border-radius: 6px;

  [tr-top] {
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    background-color: #0062A5;
    color: #FFFFFF;
    padding: 25px;

    [dis] {
      font-size: 24px;
      font-weight: bold;
      padding-left: 10px;
      border-left: 4px solid #1890ff;

      div:nth-child(2) {
        font-size: 16px;
        font-weight: 400;
      }
    }
  }

  .route-list {
    margin: 30px 0;
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
  }

  .route-card {
    width: 22%;
    height: 230px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    background-size: cover;
    background-position: center;
    border-radius: 5px;
  }

  .card-mask {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.6) 100%);
  }

  .news-list {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0 20px;
    margin-bottom: 80px;
  }

  .news-item {
    height: 60px;
    line-height: 60px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
  }

  .news-item:last-child {
    border-bottom: none;
  }

  .news-date {
    color: #999;
    font-size: 15px;
    min-width: 90px;
  }

  .news-title {
    color: #333;
    font-size: 20px;
    margin-left: 20px;
  }
}

[tr-right] {
  flex: 1;
  margin-left: 30px;
}

/* 每个项目的容器 */
.item-wrapper {
  margin-bottom: 20px;
  border-bottom: 1px solid #eee;
  padding-bottom: 20px;
  cursor: pointer;
}

.item-wrapper:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.content-wrapper {
  display: flex;
  gap: 30px;
}


.main-image {
  width: 300px;
  height: 180px;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin: 10px 10px 10px 50px;
}

.content-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-top: 60px;
  //justify-content: center;
}

.route-item {
  display: flex;
  gap: 15px;
  align-items: flex-start;
}

.route-number {
  //font-size: 30px;
  //font-weight: bold;
  color: #037081;
  min-width: 40px;
  line-height: 1.2;
}

.route-title {
  margin: 0 0 30px 0;
  //font-size: 20px;
  color: #333;
  //font-weight: 600;
}

.route-description {
  margin: 0;
  font-size: 15px;
  color: #666;
  line-height: 1.7;
}
</style>